/**
 * 初始化服务版本详情对话框
 */
var AppVersionInfoDlg = {
    appVersionInfoData : {},
    validateFields: {
    	appId: {
            validators: {
                notEmpty: {
                    message: '服务id不能为空'
                }
            }
        },
    	versionCode: {
            validators: {
                notEmpty: {
                    message: '版本号不能为空'
                }
            }
        },
    }
};


/**
 * 关闭此对话框
 */
AppVersionInfoDlg.close = function() {
    parent.layer.close(window.parent.AppVersion.layerIndex);
}

/**
 * 验证数据是否为空
 */
AppVersionInfoDlg.validate = function () {
    $('#appVersionInfoForm').data("bootstrapValidator").resetForm();
    $('#appVersionInfoForm').bootstrapValidator('validate');
    return $("#appVersionInfoForm").data('bootstrapValidator').isValid();
}

/**
 * 提交添加,在web-fileuoload中
 */
AppVersionInfoDlg.addSubmit = function() {
    if (!this.validate()) {
        return;
    }
	var options = {
	    url:Sys.backendPath + "/appversion/add", 
	    dataType:'json',
	    success:function(res) {
	        Sys.success("添加成功!");
	        window.parent.AppVersion.table.refresh();
	        AppVersionInfoDlg.close();
	    },
	    error:function(){
	        Sys.error("添加失败!");
	    }
	}; 
	$('#appVersionInfoForm').ajaxSubmit(options);
}

/**
 * 提交修改
 */
AppVersionInfoDlg.editSubmit = function() {
    if (!this.validate()) {
        return;
    }
	var options = {
	    url:Sys.backendPath + "/appversion/update", 
	    dataType:'json',
	    success:function(res) {
	        Sys.success("修改成功!");
	        window.parent.AppVersion.table.refresh();
	        AppVersionInfoDlg.close();
	    },
	    error:function(){
	        Sys.error("修改失败!");
	    }
	}; 
	$('#appVersionInfoForm').ajaxSubmit(options);
}

$(function() {
	Sys.initValidator("appVersionInfoForm", AppVersionInfoDlg.validateFields);
});
